package dominio;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {

    private static final long serialVersionUID = 1L;
    private static HibernateUtil me;
    private SessionFactory sessionFactory;

    private HibernateUtil() {
        sessionFactory = new AnnotationConfiguration()
                  .setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect")
                .setProperty("hibernate.connection.driver_class", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
                 .setProperty("hibernate.connection.url", "jdbc:sqlserver://localhost\\dbo:1433;databaseName=executivo")
                .setProperty("hibernate.connection.username", "sa")
                //.setProperty("hibernate.connection.password", "manutencao")
                .setProperty("hibernate.connection.password", "457218")
                .setProperty("hibernate.hbm2ddl.auto", "none")
                .setProperty("hibernate.show_sql", "true")
                .setProperty("hibernate.format_sql", "true")
                .setProperty("hibernate.c3p0.acquire_increment", "1")
                .setProperty("hibernate.c3p0.idle_test_period", "100")
                .setProperty("hibernate.c3p0.max_size", "10")
                .setProperty("hibernate.c3p0.max_statements", "0")
                .setProperty("hibernate.c3p0.min_size", "5")
                .setProperty("hibernate.c3p0.timeout", "100")
                 .addAnnotatedClass(Aluno.class)
                .addAnnotatedClass(Avaliacao.class)
                .addAnnotatedClass(Disciplinas.class)
                .addAnnotatedClass(Etapa.class)
                .addAnnotatedClass(Matricula.class)
                .addAnnotatedClass(NotaAvaliacao.class)
                .addAnnotatedClass(Notas.class)
                .addAnnotatedClass(Professores.class)
                .addAnnotatedClass(Serie.class)
                .addAnnotatedClass(TurmaDisciplina.class)
                .addAnnotatedClass(Turmas.class)
                .buildSessionFactory();
    }

    public Session getSession() {
        Session toReturn = sessionFactory.openSession();
        toReturn.beginTransaction();
        return toReturn;
    }

    public static HibernateUtil getInstance() {
        if (me == null) {
            me = new HibernateUtil();
        }
        return me;
    }

}